var map;
var infoWindow;
function getInfoWindowContent(map_data, marker_title){
	var map_data = codeDataForMap[map_data.code];
	var map_content = jq("<p></p>");
	if (map_data != undefined){
		map_content.append(jq("<h3></h3>").html(marker_title));
		var map_links = map_data['links'];
		for( lnk in map_links){
			link_url = map_links[lnk]
			if (link_url != undefined){
				var dm_link = jq("<a/>");
				dm_link.addClass("state-published");
				dm_link.attr("href", link_url[0]);
				dm_link.html(link_url[1]);
				map_content.append(dm_link);
			}													
		}
		map_content.wrapInner("<div class='mapBubble'/>")
	}
	return map_content.html();
}

function renderMap(){
	var center = new google.maps.LatLng(7.9, 21.4);
	var mapDiv = document.getElementById('google_map_three');
	map = new google.maps.Map(mapDiv, {
	center: new google.maps.LatLng(3.843, 23.512),
	zoom: 3,
	disableDoubleClickZoom: true,
	disableDefaultUI: true,
	draggable: true,
	scaleControl: false,
	mapTypeControl: false,
	navigationControl: false,
	scrollwheel: false,
	mapTypeId: google.maps.MapTypeId.ROADMAP
	});
																						
	google.maps.event.addListener(map,
	'tilesloaded',
	addContactMarkers);							
}


function addContactMarkers(){
	function createMarker(map, data){
			var marker = new google.maps.Marker(
			{
				map: map,
				position: new google.maps.LatLng(data.lat, data.lng),
				title: data.title,
				icon: "/++resource++media-logos/map/map80.png",
				clickable: true
			}
			);
			
			
			var infoWindowHtml = "";
			
			google.maps.event.addListener(marker, 'mouseover',
				function(){
					if (infoWindow){
						infoWindow.close();
					}
					infoWindow = new google.maps.InfoWindow();
					marker_title = marker.getTitle();
					infoWindowContent = getInfoWindowContent(data, marker_title);
					infoWindow.setContent(infoWindowContent);
					infoWindow.open(marker.getMap(), marker);
				});
	}

	for (mds in geoCodes){
		var md = geoCodes[mds];
		createMarker(map, md);
	}

}
google.setOnLoadCallback(renderMap);		
